# Maintainer: Nazar Mishturak <nazar m x at gmail dot com>

_realname=libbotan
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.11.30
pkgrel=1
arch=('any')
url='http://botan.randombit.net/'
pkgdesc='Botan is a C++ cryptography library released under the permissive Simplified BSD license. (mingw-w64)'
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-xz")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-sphinx"
	     "${MINGW_PACKAGE_PREFIX}-python3-imagesize")
license=('BSD')
options=('strip' 'staticlibs' 'docs')
source=(http://botan.randombit.net/releases/Botan-${pkgver}.tgz{,.asc}
        'boost-link.patch'
        'winsock-link.patch'
        'disable-mkgmtime.patch')
sha256sums=('8daf3adc8eb3b046ab4678beca5aef07af900c7781ddc88b10d1d966de66a125'
            'SKIP'
            '993bdf500ffc25b143fd28d86c978950969986ac8ed9c882df10270af46b8bbc'
            '7972cf10f74dcbc95cab2452a2604c2be25c5172fac23c471c62b7341e5a7009'
            '653facd09ea5b045115bcb148998e09ecb592b2ba163ea4618334bfa423fa490')
validpgpkeys=('621DAF6411E1851C4CF9A2E16211EBF1EFBADFBC')

prepare() {
  cd "${srcdir}/Botan-${pkgver}"
  patch -p1 -i "${srcdir}/boost-link.patch"
  patch -p1 -i "${srcdir}/winsock-link.patch"
  patch -p1 -i "${srcdir}/disable-mkgmtime.patch"
}

build() {
  rm -rf build-${MINGW_CHOST}
  cp -rf Botan-${pkgver} build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  sed -i "s|/mingw|${MINGW_PREFIX}|g" src/build-data/os/mingw.txt

  local BUILD_TYPE_FLAGS=''
  if check_option 'debug' 'y'; then
    BUILD_TYPE_FLAGS='--with-debug-info'
  fi

  # Set prefix to mingw{32,64} not full path. Remove starting slash
  ${MINGW_PREFIX}/bin/python3 configure.py \
                              --disable-shared \
                              --os=mingw \
                              --cc=gcc \
                              --cpu=${CARCH} \
                              --destdir='$(DESTDIR)' \
                              ${BUILD_TYPE_FLAGS} \
                              --makefile-style=gmake \
                              --link-method=copy \
                              --with-sphinx \
                              --with-boost \
                              --with-bzip2 \
                              --with-lzma \
                              --with-sqlite3 \
                              --with-zlib

    make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./botan-test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}${MINGW_PREFIX}" install
}
